package com.google.code.sip.ucenter.imports;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.code.sip.ucenter.dao.mongo.RoleDaoImpl;
import com.google.code.sip.ucenter.model.Role;

@Service("roleImporter")
public class RoleImporter extends AbstractImporter<Role> {
	@Autowired
	private RoleDaoImpl roleDao;

	@Override
	protected Role toEntity(Map<String, String> props) {
		Role role = new Role();
		for (Map.Entry<String, String> entry : props.entrySet()) {
			String name = entry.getKey();
			String value = entry.getValue();
			try {
				if (entityClass.getDeclaredField(name) != null) {
					beanUtilsBean.copyProperty(role, name, value);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return role;
	}

	@Override
	protected void doSave(Role role) {
		roleDao.save(role);
	}

	@Override
	protected void doInit() {
		roleDao.clear();
	}

}
